package com.wnxy.c_exec;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class App2 {
    public static void main(String[] args) {
        // 需求：任务3秒后执行
        //ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
        //executorService.schedule(()->{
        //    System.out.println(Thread.currentThread().getName());
        //},3, TimeUnit.SECONDS);

        // 需求：任务3秒后，每5秒执行一次  (nacos发送心跳就是通过这个线程池完成的每5秒发送一次心跳)
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
        executorService.scheduleAtFixedRate(()->{
            System.out.println(Thread.currentThread().getName());
        },3,5, TimeUnit.SECONDS);

    }
}
